package top.vchao.webmusicplayer;

import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.View;
import android.widget.SeekBar;

import java.io.IOException;

import top.vchao.webmusicplayer.player.Player;

public class MainActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private SeekBar mSeekBar;
    private String path = "http://file.kuyinyun.com/group1/M00/90/B7/rBBGdFPXJNeAM-nhABeMElAM6bY151.mp3";
    private Player mPlayer;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        testPlay();
//        vcplay();
//        aaa();
        Intent intent = new Intent(MainActivity.this, WebMusicActivity.class);
        startActivity(intent);
    }

    private void aaa() {
        mSeekBar = (SeekBar) findViewById(R.id.seekBar);
        mPlayer = new Player(mSeekBar);
    }

    /**
     * 播放
     *
     * @param view
     */
    public void play(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mPlayer.playUrl(path);
            }
        }).start();
    }

    public void pause(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mPlayer.pause();
            }
        }).start();
    }

    public void resume(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mPlayer.resume();
            }
        }).start();
    }


    private void vcplay() {
        mediaPlayer = new MediaPlayer();

        //设置监听：播放出错、播放完成、准备完成
        try {
            mediaPlayer.setDataSource("\"http://m10.music.126.net/20190827102932/eef47ed3ec71c2b45bae3e22e40ead73/ymusic/005d/565e/0508/778b073ff5a4fe8bfca12bcbea41e0a6.mp3\"");
        } catch (IOException e) {
            e.printStackTrace();
        }
        mediaPlayer.prepareAsync();
        mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                Log.e("zwc", "开始播放网络歌曲");
                mediaPlayer.start();
            }
        });
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.start();
            }
        });

    }

    private void testPlay() {
/*        String s = "{\"album_title\":\"沙漠骆驼\",\"artist_name\":\"展展与罗罗\",\"lrclink\":\"http://qukufile2.qianqian.com/data2/lrc/85d4f0173122c9fc5e901d4d5ef06bd2/608606729/608606729.lrc\",\"pic_big\":\"http://qukufile2.qianqian.com/data2/pic/c9aa6f85bf036735c355a05dd373ff0b/606149058/606149058.png@s_2,w_150,h_150\",\"pic_small\":\"http://qukufile2.qianqian.com/data2/pic/c9aa6f85bf036735c355a05dd373ff0b/606149058/606149058.png@s_2,w_90,h_90\",\"song_id\":\"606149060\",\"ting_uid\":\"340462058\",\"title\":\"沙漠骆驼\"}";
        OnlineMusic onlineMusic = new Gson().fromJson(s, OnlineMusic.class);

        String artist = onlineMusic.getArtist_name();
        String title = onlineMusic.getTitle();

        Music music = new Music();
        music.setType(Music.Type.ONLINE);
        music.setTitle(title);
        music.setArtist(artist);
        music.setAlbum(onlineMusic.getAlbum_title());

        // 获取歌曲播放链接
        music.setPath("http://m10.music.126.net/20190827102932/eef47ed3ec71c2b45bae3e22e40ead73/ymusic/005d/565e/0508/778b073ff5a4fe8bfca12bcbea41e0a6.mp3");
        music.setDuration(338 * 1000);

        AudioPlayer.get().addAndPlay(music);*/
    }


}
